def max_subarray_sum(arr):
    max_current = max_global = arr[0]
    for i in range(1, len(arr)):
        max_current = max(arr[i], max_current + arr[i])
        if max_current > max_global:
            max_global = max_current
    return max_global

# 测试用例
test_cases = [
    [1, -2, 3, 5, -1],
    [1, -2, 3, -8, 5, 1],
    [1, -2, 3, -2, 5, 1]
]
for case in test_cases:
    print(f"数组 {case} 的最大子数组和为：{max_subarray_sum(case)}")